package com.jas.logic;

//@author A0098803W
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.Calendar;

import org.junit.Before;
import org.junit.Test;

import com.jas.common.CommandFormatException;
import com.jas.common.DateFormatException;
import com.jas.common.Language;
import com.jas.common.Notification;
import com.jas.common.Utilities;
import com.jas.storage.StorageAPI;
import com.jas.storage.StorageException;

//@author A0098803W
/**
 * This class handles the testing of the notification timer, whether the timer
 * is monitoring the notification storage file properly.
 * 
 */
public class NotificationTimerTest {

	@Before
	public void setUp() throws Exception {
		Language.loadLanguageFile();
	}

	@Test
	public void testNotificationTimer() throws CommandFormatException,
			StorageException, DateFormatException, InterruptedException {
		Logic logic = new Logic();
		LogicAPI logicApi = new LogicAPI(logic);
		Calendar cal = Calendar.getInstance();
		int currentDay = cal.get(Calendar.DAY_OF_MONTH);
		int currentMonth = cal.get(Calendar.MONTH)+1;
		int currentYear = cal.get(Calendar.YEAR);
		int currentHour = cal.get(Calendar.HOUR_OF_DAY);
		int currentMinute = cal.get(Calendar.MINUTE)+1;
		String minuteUpdate="";
		if(currentMinute==1||currentMinute==2||currentMinute==3||currentMinute==4||currentMinute==5||currentMinute==6||currentMinute==7||currentMinute==8||currentMinute==9||currentMinute==0){
			minuteUpdate="0"+String.valueOf(currentMinute);
		}
		else{
			minuteUpdate=String.valueOf(currentMinute);
		}
		
		String date=String.valueOf(currentDay)+"/0"+String.valueOf(currentMonth)+"/"+String.valueOf(currentYear)
				+"/"+String.valueOf(currentHour)+":"+minuteUpdate;
		System.out.println(date);
		
		Notification newNotification4 = logicApi.add(date.trim(),
				"dd/MM/yyyy/HH:mm", "This is a test message.");
		@SuppressWarnings("unchecked")
		ArrayList<Notification> notificationList = (ArrayList<Notification>) StorageAPI
				.loadNotificationList();
		assertFalse(notificationList.isEmpty());
		Thread.sleep(120000);
		notificationList = (ArrayList<Notification>) StorageAPI
				.loadNotificationList();
		assertTrue(notificationList.isEmpty());
		

	}

}
